package com.bskj.kuaifu.service.impl;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.bskj.common.bean.model.ParkLotWechatPayInfo;
import com.bskj.common.bean.model.ParkingLotCustomer;
import com.bskj.common.constants.ReturnCodeMsgConstants;
import com.bskj.common.dao.ParkLotWechatPayInfoDao;
import com.bskj.common.dao.ParkingLotCustomerDao;
import com.bskj.common.dao.core.BaseDao;
import com.bskj.common.dao.core.FindRequestEntity;
import com.bskj.common.dao.core.WhereEnum;
import com.bskj.common.service.impl.BaseServiceImpl;
import com.bskj.kuaifu.service.IParkingLotCustomerService;

@Service
public class ParkingLotCustomerServiceImpl extends BaseServiceImpl<ParkingLotCustomer> implements
		IParkingLotCustomerService {
	@Autowired
	private ParkingLotCustomerDao parkingLotCustomerDao;
	
	@Autowired
	private ParkLotWechatPayInfoDao parkLotWechatPayInfoDao;

	public BaseDao<ParkingLotCustomer> getBaseDao() {
		return parkingLotCustomerDao;
	}

	public Map<String, Object> validParkLot(Integer parkLotId, String parkLotUuid) throws Exception {
		Map<String, Object> resultMap = new HashMap<>();
		ParkingLotCustomer parkingLot = get(parkLotId);
		if (parkingLot == null) {
			resultMap.put("resultCode", ReturnCodeMsgConstants.REQUEST_INVALID);
			resultMap.put("resultMsg", "停车场不存在!");
			return resultMap;
		} else {
			if (!parkingLot.getUuid().equals(parkLotUuid)) {
				resultMap.put("resultCode", ReturnCodeMsgConstants.REQUEST_INVALID);
				resultMap.put("resultMsg", "停车场信息不合法!");
				return resultMap;
			}
		}
		resultMap.put("parkingLot", parkingLot);
		return resultMap;
	}

	@Override
	public ParkLotWechatPayInfo getWechatPayInfo(Integer parkLotId) throws Exception {
		FindRequestEntity findWechatPayInfoReq = new FindRequestEntity();
		findWechatPayInfoReq.addWhere("park_lot_customer_id", WhereEnum.EQ, parkLotId);
		List<ParkLotWechatPayInfo> payInfoList = parkLotWechatPayInfoDao.find(findWechatPayInfoReq);
		if(payInfoList != null && payInfoList.size() > 0) {
			return payInfoList.get(0);
		}
		return null;
	}
}
